'''
    Module used to validate the input
'''
# validate fields
from validators import ipv4, domain
# used to get the current public IP
from json import load
from urllib2 import urlopen
# colors
from vars import ccolors

# validate the input based on the passed args
def validateInput(args):
    if not args.victim or not args.targetDomain or not args.addressToForge:
        return False
    if not ipv4(args.victim):
        print ccolors.WARNING + 'Victim is not a valid IP address\n' + ccolors.FAIL + 'Terminating...'  + ccolors.NC
        return False

    if not domain(args.targetDomain): #supports IDN
        print ccolors.WARNING + 'Target is not a valid domain\n' + ccolors.FAIL + 'Terminating...'  + ccolors.NC
        return False

    if args.addressToForge == 'myip' or args.addressToForge == 'myIP':
        # get user's current IP address from this URL
        args.addressToForge = load(urlopen('http://jsonip.com'))['ip']
    elif not ipv4(args.addressToForge):
        print ccolors.WARNING + 'Spoofing IP is not a valid IP address\n' + ccolors.FAIL + 'Terminating...' + ccolors.NC
        return False

    if args.demo and not ipv4(args.demo):
        print ccolors.WARNING + 'Demo IP is not a valid IP address\n' + ccolors.FAIL + 'Terminating...' + ccolors.NC
        return False

    return True
